home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / SourceCode / Registration / send.m < prev   
Text File  |  1992-12-19  |  989b  |  53 lines

  1. /*
  2.  * send.m:
  3.  * do a UDP broadcast
  4.  */
  5.  
  6. #import "Registration.h"
  7. #include <sys/types.h>
  8. #include <sys/socket.h>
  9. #import <pwd.h>
  10. #import <netinet/in.h>
  11. #import <netdb.h>
  12.  
  13. main(int argc,char **argv)
  14. {
  15.     struct  sockaddr_in sin;
  16.     struct    servent *sp;
  17.     int    sock;
  18.     int    cc;
  19.     struct  hostent *host = 0;
  20.     struct    regNetToken nt;
  21.     struct    passwd    *pw;
  22.  
  23.     sin.sin_family    = AF_INET;
  24.     sin.sin_port    = 45743;    /* our port */
  25.  
  26.     host    = gethostbyname("broadcasthost");
  27.     sin.sin_family    = host->h_addrtype;
  28.     memcpy(&sin.sin_addr,host->h_addr_list[0],host->h_length);
  29.  
  30.     sock    = socket(AF_INET,SOCK_DGRAM,0); /* get a socket */
  31.  
  32.     argc--;
  33.     argv++;
  34.  
  35.     memset(&nt,0,sizeof(nt));
  36.  
  37.     pw    = getpwuid(getuid());
  38.  
  39.     strncpy(nt.username,pw->pw_name,sizeof(nt.username)-1);
  40.     strncpy(nt.person,pw->pw_gecos,sizeof(nt.person)-1);
  41.  
  42.     nt.command    = C_PRINT;
  43.     while(argc){
  44.         strcat(nt.userData,*argv);
  45.         strcat(nt.userData," ");
  46.         argc--;
  47.         argv++;
  48.     }
  49.  
  50.     cc    = sendto(sock,&nt,sizeof(nt),0,(struct sockaddr *)&sin,sizeof(sin));
  51.     exit(0);
  52. }
  53.